package com.newsproject.controller;

import Util.PageInfo;
import Util.SessionUtils;

import com.newsproject.pojo.*;
import com.newsproject.pojo.DTO.*;
import com.newsproject.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;


import javax.servlet.http.HttpSession;
import java.util.List;

@Api(tags = "管理员管理" , description = "管理员管理相关接口")
@RequestMapping("/AdminController")
@Controller
public class AdminController {

    @Autowired
    private AdminService adminService;

/* 用户管理表现层 */

//获取用户列表
    @ApiOperation(value = "获取用户列表(含搜索列表)", notes = "分页获取用户列表(同时包括用户搜索列表)")
    @GetMapping("/users")
    public String getUsers(Model model,
                        @RequestParam(defaultValue = "1") int currentPage,
                        @RequestParam(defaultValue = "7") int pageSize,
                        @RequestParam(required = false) String keyword,
                        @RequestParam(defaultValue = "user_manageUser_manage") String module) {
        //调用Service层获取完整分页数据
        UserListResponseDTO responseDTO = adminService.getUserList(currentPage, pageSize, keyword);
        //将数据添加到模型中用于渲染页面
        model.addAttribute("users", responseDTO.getUsers());
        model.addAttribute("activeModule", module);
        model.addAttribute("totalPages",responseDTO.getTotalPages());
        model.addAttribute("pageInfo", responseDTO.getPageInfo());
        model.addAttribute("keyword",keyword);
        //返回用户列表页面
        return "admin";
    }

/*
required = true（默认值）：表示该参数是必须的 如果请求中没有提供这个参数，Spring会抛出MissingServletRequestParameterException
required = false 表示该参数是可选的 如果请求中没有提供这个参数，参数值会是null（对于对象类型）或默认值（对于基本类型）

将用户列表和分页信息添加到模型中,PageInfo类用于封装分页相关信息
Model:是Spring MVC中的一个接口,用于在控制器方法和视图之间传递数据。
@Valid:主要用途是对方法参数、方法返回值或者类的属性开展数据校验。借助@Valid注解，你可以在程序里更便捷地保证输入数据的有效性与完整性，避免因无效数据引发的错误。
BindingResult:是一个接口，主要用于存储和处理数据绑定（将请求参数绑定到Java对象)和验证的结果。它通常与 @Valid 或 @Validated 注解配合使用，在处理表单提交或接收请求数据时发挥重要作用。
@Validated:是Spring框架提供的一个接口，用于标记需要进行数据验证的类或方法,用于在数据绑定和验证过程中进行验证。
*/

//添加用户
    @ApiOperation(value = "添加用户", notes = "处理弹窗表单的用户添加请求")
    @PostMapping("users/add")
    public String addUser(@Validated @RequestBody User user, BindingResult result,
                          RedirectAttributes redirectAttributes,Model model) {
        if (result.hasErrors()) {
            redirectAttributes.addFlashAttribute("addUserError", "用户添加失败");
            return "admin";
        } else {
            adminService.addUser(user);
            redirectAttributes.addFlashAttribute("message", "用户添加成功");
        }
        return "redirect:/AdminController/users";
    }

//用户编辑
    @ApiOperation(value = "用户编辑", notes = "处理用户更新表单提交")
    @PostMapping("users/update/{id}")
    @ResponseBody
    public Result<?> updateUser(@PathVariable("id") int id,@Validated User user) {
     try {
         user.setUserId(id);   //绑定用户信息
         adminService.updateUser(user);
       return  Result.success(user,"用户更新成功");
    } catch(Exception e) {
         return Result.error(409,e.getMessage());
     }
    }

//用户删除操作
    @ApiOperation(value = "删除单个用户", notes = "删除指定ID的用户")
    @PostMapping("/users/delete/{id}")
    public String deleteUser(@PathVariable("id") int id, RedirectAttributes redirectAttributes) {
        adminService.deleteUserById(id);
        redirectAttributes.addFlashAttribute(Result.success("删除成功"));
        return "redirect:/AdminController/users";
    }

//批量删除用户
    @ApiOperation(value = "批量删除用户", notes = "批量删除指定ID的用户")
    @PostMapping("/users/batch-delete")
    public String deleteUserBatch(@RequestParam("ids") int[] ids, RedirectAttributes redirectAttributes) {
            adminService.deleteUserByIds(ids);
            redirectAttributes.addFlashAttribute(Result.success("批量删除成功"));
        return "redirect:/AdminController/users";
    }

//批量设置用户权限管理
    @ApiOperation(value = "批量设置用户权限", notes = "批量设置用户的权限设置")
    @PostMapping("/users/batch-permissions")
    public String updatePermissions(@RequestBody List<UserStatus> updateList, RedirectAttributes redirectAttributes) {
        adminService.batchUpdateUserPermissions(updateList);
        redirectAttributes.addFlashAttribute("success", "用户状态批量更新成功!");
        return "redirect:/AdminController/users";
    }

//设置禁言权限
    @ApiOperation(value = "设置用户禁言权限", notes = "设置指定ID的用户的禁言权限")
    @PostMapping("/users/ban/{id}")
    public String ban(@PathVariable("id") int id,@RequestParam boolean enable, RedirectAttributes redirectAttributes) {
        adminService.banUser(id, enable);
        redirectAttributes.addFlashAttribute("message", "用户已被禁言");
        return "redirect:/AdminController/users";
    }

//设置私信权限
    @ApiOperation(value = "用户私信权限设置", notes = "设置指定ID的用户的私信权限")
    @PostMapping("/users/privateMessage/{id}")
    public String privateMessage(@PathVariable("id") int id,
                                 @RequestParam boolean enable,RedirectAttributes redirectAttributes) {
        adminService.setPrivateMessagePermission(id, enable );
        redirectAttributes.addFlashAttribute("message", "用户已不能发送私信");
        return "redirect:/AdminController/users";
    }

//设置账号权限
    @ApiOperation(value = "用户账号权限设置", notes = "设置指定ID的用户的账号权限")
    @PostMapping("/users/banAccount/{id}")
    public String banAccount(@PathVariable("id") int id, @RequestParam boolean enable,RedirectAttributes redirectAttributes) {
        adminService.setBanAccountPermission(id, enable);
        redirectAttributes.addFlashAttribute("message", "用户账号已被封禁");
        return "redirect:/AdminController/users";
    }

//根据id获取用户信息
@ApiOperation(value="根据用户id获取用户信息")
@GetMapping("/users/{userId}")
@ResponseBody
 public ResponseEntity<User> getUserById(@PathVariable("userId") int userId, Model model){
       User user = adminService.getUserById(userId);
       model.addAttribute("user",user);
       return ResponseEntity.ok(user);
}


/* 热搜管理表现层 */

//获取热搜列表
    @ApiOperation(value = "获取热搜列表(含搜索列表)", notes = "分页获取热搜信息(同时包括热搜搜索列表)")
    @GetMapping("/hotSearch")
    public String hotSearch(Model model,
                            @RequestParam(defaultValue = "1") int currentPage,
                            @RequestParam(defaultValue = "7") int pageSize,
                            @RequestParam(required = false) String keyword,
                            @RequestParam(defaultValue = "hot_search") String module) {
        //调用Service层获取完整分页数据
        HotSearchListResponseDTO responseDTO = adminService.getHotSearchList(currentPage, pageSize,keyword);
        //调用Service层获取热搜总数
        model.addAttribute("hotSearches", responseDTO.getHotSearches());
        model.addAttribute("totalPages",responseDTO.getTotalPages());
        model.addAttribute("activeModule", module);
        model.addAttribute("keyword",keyword);
        model.addAttribute("pageInfo", responseDTO.getPageInfo());

        return "admin";
    }

//展示热搜信息
@ApiOperation(value = "展示热搜信息", notes = "用于展示热搜信息")
@GetMapping("hotSearch/showInfo/{hotSearchId}")
 public String showHotSearchInfo(@PathVariable("hotSearchId") int hotSearchId, Model model) {
        HotSearch hotSearch = adminService.getHotSearchById(hotSearchId);
        model.addAttribute("hotSearch", hotSearch);
        return "hotSearchAudit";
    }

//提交热搜部分信息的编辑
    @ApiOperation(value = "提交热搜部分信息编辑", notes = "处理编辑的热搜部分信息表单提交(返回到热搜编辑页面)")
    @PostMapping("hotSearch/update/{id}")
    public String hotSearchEditSubmit(@PathVariable("id") int hotSearchId, @Validated HotSearchPostDTO hotSearchPostDTO,
                                      BindingResult result, RedirectAttributes redirectAttributes) {

        hotSearchPostDTO.setHotSearchId(hotSearchId);
        if (result.hasErrors()) {
            return "admin";
        }
        if (hotSearchPostDTO.getHotSearchId() <= 0) {
            redirectAttributes.addFlashAttribute("error", "热搜ID无效");
        } else {
            adminService.updateHotSearch(hotSearchPostDTO);
            redirectAttributes.addFlashAttribute("message", "热搜更新成功");
        }
        return "redirect:/AdminController/hotSearch";
    }

//修改热搜状态(是否屏蔽)
    @ApiOperation(value = "修改热搜状态(是否屏蔽)", notes = "设置热搜的屏蔽操作(在主页面进行)")
    @PostMapping("/hotSearch/block/{hot_search_id}")
    public String updateHotSearchBlocked(@PathVariable("hot_search_id") int hot_search_id, @RequestParam boolean enable,RedirectAttributes redirectAttributes) {
        adminService.updateHotSearch_Blocked(hot_search_id, enable);
        redirectAttributes.addFlashAttribute("message", "热搜屏蔽成功!");
        return "redirect:/AdminController/hotSearch";
    }

//修改热搜状态(是否限流)
    @ApiOperation(value = "修改热搜状态(是否限流)", notes = "设置热搜的限流操作(在主页面进行)")
    @PostMapping("/hotSearch/limit/{hot_search_id}")
    public String updateHotSearchLimited(@PathVariable("hot_search_id") int hot_search_id,@RequestParam boolean enable, RedirectAttributes redirectAttributes) {
        adminService.updateHotSearch_Limited(hot_search_id, enable);
        redirectAttributes.addFlashAttribute("message", "热搜限流成功!");
        return "redirect:/AdminController/hotSearch";
    }

//批量更新热搜状态
    @ApiOperation(value = "批量修改热搜状态", notes = "批量设置热搜状态")
    @PostMapping("/hotSearch/batchUpdateHotSearchStatus")
    public String batchUpdateHotSearchStatus(@RequestBody List<HotSearch> hotSearchIds, RedirectAttributes redirectAttributes) {

        adminService.updateHotSearchStatusByIds(hotSearchIds);
        redirectAttributes.addFlashAttribute("message", "批量更新热搜状态成功");
        return "redirect:/AdminController/hotSearch";
    }

//删除单个热搜
    @ApiOperation(value = "删除单个热搜", notes = "用于删除热搜(此操作在主页面)")
    @PostMapping("/hotSearch/deleteSingle/{horSearchId}")
    public String deleteSingle(@PathVariable("horSearchId") int hotSearchId, RedirectAttributes redirectAttributes) {

        adminService.deleteHotSearchById(hotSearchId);
        redirectAttributes.addFlashAttribute("success", "删除成功!");
        return "redirect:/AdminController/hotSearch";
    }

//批量删除热搜
    @ApiOperation(value = "批量删除热搜", notes = "用于批量删除热搜(此操作在主页面进行)")
    @PostMapping("/hotSearch/deleteBatch/{hotSearchIds}")
    public String deleteHotSearchBatch(@RequestParam("hotSearchIds") int[] hotSearchIds, RedirectAttributes redirectAttributes) {

                adminService.deleteHotSearchBatch(hotSearchIds);
                redirectAttributes.addFlashAttribute("success", "批量删除成功");
                return "redirect:/AdminController/hotSearch";
    }

//根据postId获取新闻信息
@ApiOperation(value="根据新闻Id获取新闻信息")
@GetMapping("/hotSearch/{postId}")
@ResponseBody
    public ResponseEntity<Post> getHotSearchByPostId(@PathVariable("postId") int postId, Model model){
        Post post = adminService.getPostById(postId);
        model.addAttribute("post",post);
        return ResponseEntity.ok(post);
    }

//根据热搜id获取热搜信息
@ApiOperation(value="根据热搜Id获取热搜信息")
//@SentinelResource(value="getHotSearch",blockHandler="handleHotSearchLimit" )
@GetMapping("/hotSearch/hot/{hotSearchId}")
@ResponseBody
    public ResponseEntity<HotSearchPostDTO> getHotSearchDTOById(@PathVariable("hotSearchId") int hotSearchId, Model model){
    HotSearchPostDTO hotSearchDTO = adminService.getHotSearchDTOById(hotSearchId);
        model.addAttribute("hotSearchDTO",hotSearchDTO);
        return ResponseEntity.ok(hotSearchDTO);
}

/*//限流降级处理方法
public Result<?> handleHotSearchLimit(int hotSearchId, BlockException ex){
    return Result.error("当前热搜访问量过大,请稍后再试");
}*/

/* 管理员对标签的管理 */

//获取标签列表
    @ApiOperation(value = "获取所有标签(含搜索列表)", notes = "获取标签列表(同时包括标签搜索列表)")
    @GetMapping("/tag")
    public String getAllTag(Model model,@RequestParam(defaultValue = "tag_manage") String module,
                            @RequestParam(required = false) String keyword) {
        List<Tag> tagList;
    //根据关键字搜索标签列表实现逻辑
        if(keyword!= null &&!keyword.isEmpty()){
        //执行搜索逻辑
            tagList = adminService.searchTag(keyword);
        }  else {
        //执行标签正常展示逻辑
            tagList = adminService.getTagList();
        }

        model.addAttribute("activeModule", module);
        model.addAttribute("pageInfo", new PageInfo(1, tagList.size(), tagList.size()));
        model.addAttribute("keyword",keyword);
        model.addAttribute("tagList", tagList);
        return "admin";
    }

//添加标签
    @ApiOperation(value = "添加标签", notes = "处理添加标签表单提交")
    @PostMapping("tag/add")
    public String addTagSubmit(@Validated Tag tag, RedirectAttributes redirectAttributes,Model model) {

        adminService.insertTag(tag);
        redirectAttributes.addFlashAttribute("message", "类别添加成功");
        return "redirect:/AdminController/tag";
    }

//修改标签状态
@ApiOperation(value = "修改标签状态", notes = "修改标签状态")
@PostMapping("/tag/updateStatus")
   public String updateCategorySubmit(@Validated Tag tag,RedirectAttributes redirectAttributes) {

            adminService.updateTag(tag);
            redirectAttributes.addFlashAttribute("message", "类别更新成功");
        return "redirect:/AdminController/tag";
    }

//删除标签
@ApiOperation(value="删除标签",notes="删除单个标签")
@PostMapping("/tag/delete/{tagId}")
    public String deleteTagById(@PathVariable int tagId, RedirectAttributes redirectAttributes) {

       adminService.deleteTagById(tagId);
       redirectAttributes.addFlashAttribute("message","删除成功");
       return "redirect:/AdminController/tag";
}

//批量删除标签
@ApiOperation(value="批量删除标签",notes="用于批量删除标签")
@PostMapping("/tag/deleteBatchTag")
    public String deleteTagBatch(@RequestParam("tagIds") int[] tagIds, RedirectAttributes redirectAttributes) {

        adminService.deleteTagByIds(tagIds);
        redirectAttributes.addFlashAttribute("message","批量删除成功");
        return "redirect:/AdminController/tag";
    }

//编辑标签
@ApiOperation(value="编辑标签",notes="编辑标签")
@PostMapping("/tag/edit/{tagId}")
    public String editTag(@PathVariable int tagId,@Validated Tag tag,BindingResult result, RedirectAttributes redirectAttributes) {
        //绑定标签信息
        tag.setTagId(tagId);
        if(result.hasErrors()){
            return "admin";
        }
        adminService.editTagById(tag);
        redirectAttributes.addFlashAttribute("message","标签编辑成功");
        return "redirect:/AdminController/tag";
    }


/* 管理员审核 */

//1.获取待审核新闻列表
@ApiOperation(value="获取待审核新闻列表",notes="获取待审核新闻列表")
@GetMapping("/audit")
    public String getAuditPostList(Model model,
                                   @RequestParam(defaultValue = "1") int currentPage,
                                   @RequestParam(defaultValue = "7") int pageSize,
                                   @RequestParam(required = false) String keyword,
                                   @RequestParam(defaultValue="article_review") String module) {
    AuditPostResponseDTO responseDTO = adminService.getAuditingPostList(currentPage, pageSize,keyword);

    model.addAttribute("auditPostList",responseDTO.getAuditPostList());
    model.addAttribute("totalPages",responseDTO.getTotalPages());
    model.addAttribute("activeModule",module);
    model.addAttribute("pageInfo",responseDTO.getPageInfo());
    model.addAttribute("keyword",keyword);
    return "admin";
 }

//2.审核通过
@ApiOperation(value="审核通过",notes="审核通过")
@PostMapping("/audit/approve/{postId}")
    public String approvePost(@PathVariable("postId") int postId,RedirectAttributes redirectAttributes,HttpSession session) {
    try {
        SessionUtils.checkAdminSession(session);
        User adminUser = (User) session.getAttribute("userInfo");
        adminService.updatePostAuditing(postId, adminUser);
        redirectAttributes.addFlashAttribute("success", "审核通过!");
        return "redirect:/AdminController/audit";
    } catch(SessionUtils.SessionCheckException e) {
     redirectAttributes.addFlashAttribute("error",e.getErrorMessage());
     return e.getRedirectUrl();
    }catch(Exception e){
        redirectAttributes.addFlashAttribute("error",e.getMessage());
        return "redirect:/AdminController/audit";
    }
}

//3.审核未通过
@ApiOperation(value="审核未通过",notes="审核未通过")
@PostMapping("/audit/reject/{postId}")
    public String rejectPost(@PathVariable int postId,String auditReason,RedirectAttributes redirectAttributes,HttpSession session){
    try {
        SessionUtils.checkAdminSession(session);
        User adminUser = (User) session.getAttribute("userInfo");
        adminService.updatePostNotAuditing(postId,adminUser,auditReason);
        redirectAttributes.addFlashAttribute("success", "审核通过!");
        return "redirect:/AdminController/audit";
    } catch(SessionUtils.SessionCheckException e) {
        redirectAttributes.addFlashAttribute("error",e.getErrorMessage());
        return e.getRedirectUrl();
    }catch(Exception e){
        redirectAttributes.addFlashAttribute("error",e.getMessage());
        return "redirect:/AdminController/audit";
    }
}

//4.批量审核通过
@ApiOperation(value="批量审核通过",notes="批量审核通过")
@PostMapping("/audit/approveBatch/approveBatchPost")
    public String approveBatch(@RequestParam("postIds") int []postIds, RedirectAttributes redirectAttributes, HttpSession session){
    try {
        SessionUtils.checkAdminSession(session);
        User adminUser = (User) session.getAttribute("userInfo");
        adminService.updatePostAuditingBatch(postIds, adminUser);
        redirectAttributes.addFlashAttribute("success", "审核通过!");
        return "redirect:/AdminController/audit";
    } catch(SessionUtils.SessionCheckException e) {
        redirectAttributes.addFlashAttribute("error",e.getErrorMessage());
        return e.getRedirectUrl();
    }catch(Exception e){
        redirectAttributes.addFlashAttribute("error",e.getMessage());
        return "redirect:/AdminController/audit";
    }
  }

//5.批量审核未通过
@ApiOperation(value="批量审核未通过",notes="批量审核未通过")
@PostMapping("/audit/rejectBatch/rejectBatchPost")
    public String rejectBatch(@RequestParam("postIds") int []postIds,String auditReason,RedirectAttributes redirectAttributes,HttpSession session) {
    try {
        SessionUtils.checkAdminSession(session);
        User adminUser = (User) session.getAttribute("userInfo");
        adminService.updatePostNotAuditingBatch(postIds, adminUser,auditReason);
        redirectAttributes.addFlashAttribute("success", "审核通过!");
        return "redirect:/AdminController/audit";
    } catch(SessionUtils.SessionCheckException e) {
        redirectAttributes.addFlashAttribute("error",e.getErrorMessage());
        return e.getRedirectUrl();
    }catch(Exception e){
        redirectAttributes.addFlashAttribute("error",e.getMessage());
        return "redirect:/AdminController/audit";
    }
}

//6.获取审核记录(分页查询)
@ApiOperation(value="审核记录表",notes="用于获取审核记录")
@GetMapping("/auditLog")
   public String getAuditLog(@RequestParam(defaultValue = "1") int currentPage,
                             @RequestParam(defaultValue = "7") int pageSize,
                             @RequestParam(required = false) String keyword,
                             @RequestParam(defaultValue="review_form") String module,
                             Model model){
    AuditPostLogResponseDTO responseDTO = adminService.getAuditedPostList(keyword,currentPage,pageSize);

    model.addAttribute("keyword",keyword);
    model.addAttribute("activeModule",module);
    model.addAttribute("totalPages",responseDTO.getTotalPages());
    model.addAttribute("auditPost",responseDTO.getAuditPost());
    model.addAttribute("pageInfo",responseDTO.getPageInfo());
    return "admin";
}


//7.删除审核记录
@ApiOperation(value="删除单个审核记录",notes="对单个审核记录删除(此操作在主页面)")
@PostMapping("/auditLog/deleteSingleAuditPost/{auditId}")
    public String deleteSingleAuditPost(@PathVariable("auditId") int auditId, RedirectAttributes redirectAttributes){
       adminService.deleteAuditedPostById(auditId);
       redirectAttributes.addFlashAttribute("success","删除成功!");
       return "redirect:/AdminController/audit";
}

//8.批量删除审核记录
@ApiOperation(value="批量删除审核记录",notes="删除多个审核记录(此操作在主页面进行)")
@PostMapping("/auditLog/deleteBatchAuditPost/batch_delete_auditPost")
    public String deleteAuditedPostByIds(@RequestParam() int []auditIds,RedirectAttributes redirectAttributes){

    adminService.deleteAuditedPostByIds(auditIds);
    redirectAttributes.addFlashAttribute("success","批量删除成功!");
    return "redirect:/AdminController/audit";
}

}




/*
2.添加热搜的页面
    @ApiOperation(value = "添加热搜", notes = "添加新的热搜信息")
    @GetMapping("hotSearch/add")
    public String hotSearchAdd(Model model) {
        model.addAttribute("hotSearch", new HotSearch());
        return "admin_hotSearch_add.html";
    }
    //提交添加
    @ApiOperation(value = "提交热搜添加(注意:此接口不用写!!!)", notes = "处理热搜添加表单提交")
    @PostMapping("hotSearch/add")
    public String hotSearchAddSubmit(@Validated HotSearch hotSearch, BindingResult result,
                                     @Validated Post post, RedirectAttributes redirectAttributes,
                                     HttpSession session) {
        if (result.hasErrors()) {
            return "admin_hotSearch_add.html";
        }
        if (hotSearch.getKeyword() == null) {
            hotSearch.setKeyword(""); // 设置为空字符串或其他默认值
        }
        Integer Id = (Integer) session.getAttribute("Id");
        post.setUserId(Id);

        adminService.addPost(post);
        adminService.addHotSearch(hotSearch);
        redirectAttributes.addFlashAttribute("message", "热搜添加成功");
        return "redirect://AdminController/hotSearch";
    }
*/


/*
搜索用户(模糊查询,分页展示)
    @ApiOperation(value = "模糊查询用户", notes = "根据关键字搜索用户信息")
    @PostMapping("/users/search")
    public String searchUsers(@RequestParam("keyword") String keyword,
                              @RequestParam(defaultValue = "1") int currentPage,
                              @RequestParam(defaultValue = "10") int pageSize,
                              Model model) {
        int start = (currentPage - 1) * pageSize;
        List<UserDTO> users = adminService.searchUsers(keyword,start,pageSize);
        //获取搜索结果的总数量
        int totalCount = adminService.searchUsers(keyword,start,pageSize).size();
        //计算总页数
        int totalPages = (int) Math.ceil((double) totalCount / pageSize);
        //将搜索结果和分页信息添加到模型中
        model.addAttribute("users", users);
        model.addAttribute("totalPages", totalPages);
        model.addAttribute("pageInfo", new PageInfo(totalCount,pageSize,currentPage));

        return "admin";
    }*/


/*
11.查询热搜
    @ApiOperation(value = "模糊查询热搜", notes = "用于查询热搜内容(此操作在主页面)")
    @PostMapping("/hotSearch/search")
    public String searchHotSearches(@RequestParam("keyword") String keyword,
                                    @RequestParam(defaultValue="1") int currentPage,
                                    @RequestParam(defaultValue="10") int pageSize,
                                    Model model) {
        //计算起始偏移量
        int start = (currentPage - 1) * pageSize;
        List<HotSearchPostDTO> hotSearches = adminService.searchHotSearch(keyword,start,pageSize);
        //获取搜索结果的总数量
        int totalCount = hotSearches.size();
        //计算总页数
        int totalPages = (int) Math.ceil((double) totalCount / pageSize);
        //1.参数校验
        if (keyword == null || keyword.length() <= 0) {
            model.addAttribute("keyword", "关键词无效");
            return "admin";
        }
        //2.执行方法
        model.addAttribute("totalPages",totalPages);
        model.addAttribute("keyword", keyword);
        model.addAttribute("hotSearches", hotSearches);
        model.addAttribute("pageInfo",new PageInfo(totalCount,pageSize,currentPage));
        return "admin";
    }*/

/*
6.查询标签
@ApiOperation(value="查询标签",notes="用于查询标签")
@PostMapping("/tag/search")
    public String searchTag(@RequestParam("keyword") String keyword, Model model) {
        //1.参数校验
        if(keyword == null || keyword.length() <= 0){
            model.addAttribute("keyword","关键词无效");
            return "admin";
        }
        else{
            List<Tag> tagList = adminService.searchTag(keyword);
            model.addAttribute("keyword", keyword);
            model.addAttribute("categoryList", tagList);
            return "admin";
        }
    }*/


/*//6.查询审核记录
@ApiOperation(value="查询审核记录",notes="用于查询审核记录(此操作在主页面进行)")
@PostMapping("/auditLog/search")
    public String searchAuditLog(@RequestParam("keyword") String keyword,Model model){
       //1.参数校验
    if(keyword == null || keyword.length() <= 0){
        model.addAttribute("keyword","关键词无效!");
        return "admin";
    }
       //2.执行方法
    else{
     List<AuditPost> auditPostList = adminService.searchAuditedPost(keyword);
     model.addAttribute("keyword",keyword);
     model.addAttribute("auditPostList",auditPostList);
     return "admin";
    }
}*/